// from http://harmattan-dev.nokia.com/docs/library/html/guide/html/Developer_Library_Best_practices_for_application_development_Storing_and_managing_application_settings_Example_of_storing_settings_directly_to_GConf.html

#include <QDebug>
#include "gconfitemqmlproxy.h"

GConfItemQmlProxy::GConfItemQmlProxy(QObject *parent) :
   QObject(parent)
{
   _gconfItem = NULL;
   _key = "";
}

const QString & GConfItemQmlProxy::key()
{
   return _key;
}

void GConfItemQmlProxy::setKey(const QString &newKey)
{
   if (_gconfItem) {
       delete _gconfItem;
   }
   _gconfItem = new GConfItem(newKey);
   _key = newKey;

   connect(_gconfItem, SIGNAL(valueChanged()), this, SLOT(updateValue()));
}

const QVariant & GConfItemQmlProxy::value()
{
   _value = _gconfItem->value(_defaultValue);
   return _value;
}

void GConfItemQmlProxy::setValue(const QVariant &newValue)
{
   if (_gconfItem) {
       _gconfItem->set(newValue);
       _value = newValue;
   }
}

const QVariant & GConfItemQmlProxy::defaultValue()
{
   return _defaultValue;
}

void GConfItemQmlProxy::setDefaultValue(const QVariant &newValue)
{
   _defaultValue = newValue;
}

void GConfItemQmlProxy::updateValue()
{
   _value = _gconfItem->value(_defaultValue);
   emit valueChanged();
}
